package com.paic.mhis.hcpms.assessment.util;

import java.util.ArrayList;
import java.util.List;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RectangleEdge;

import com.paic.mhis.hcpms.assessment.dto.SecondLevelIndicatorDto;

/**  
 * Description: 蜘蛛网JFreeChart对象工厂
 * @author:     EX-ZENGYUANCHAO001
 * @version:    
 */
public class ScaleSpriderWebPlotFactory {

	private ScaleSpriderWebPlotFactory() {

	}

	/**
	 * 
	 * Description: 根据数据生成图表对象JFreeChart
	 * @param title 图表的名称
	 * @param legendtitleList 绘图区域名称集合 
	 * @param indicatorList   本期、上期、同等级医院平均二级指标集合
	 * @return 图表对象JFreeChart对象
	 * 
	 * Modification History:  
	 * Date        Version       Author          Description  
	 * ------------------------------------------------------------------  
	 * 2015-3-11    mhis_hcpms     EX-ZENGYUANCHAO001     创建
	 */
	public static JFreeChart createChart(String title,
			List<String> legendtitleList,
			List<ArrayList<SecondLevelIndicatorDto>> indicatorList) {
		ScaleSpiderWebPlot spiderwebplot = new ScaleSpiderWebPlot(
				createDataset(legendtitleList, indicatorList));

		JFreeChart jfreechart = new JFreeChart(title, TextTitle.DEFAULT_FONT,
				spiderwebplot, false);
		LegendTitle legendtitle = new LegendTitle(spiderwebplot);
		legendtitle.setPosition(RectangleEdge.RIGHT);
		jfreechart.addSubtitle(legendtitle);

		return jfreechart;
	}

	/**
	 * 
	 * Description: 生成数据源集合DataSet对象   
	 * @param legendtitleList
	 * @param indicatorList
	 * @return 数据源集合DefaultCategoryDataset对象
	 * 
	 * Modification History:  
	 * Date        Version       Author          Description  
	 * ------------------------------------------------------------------  
	 * 2015-3-11    mhis_hcpms     EX-ZENGYUANCHAO001     创建
	 */
	public static DefaultCategoryDataset createDataset(
			List<String> legendtitleList,
			List<ArrayList<SecondLevelIndicatorDto>> indicatorList) {

		DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
		for (int i = 0; i < legendtitleList.size(); i++) {
			String legendtitle = legendtitleList.get(i);
			List<SecondLevelIndicatorDto> siDtoList = indicatorList.get(i);
			for (SecondLevelIndicatorDto siDto : siDtoList) {
				defaultcategorydataset.addValue(siDto.getStructureScore(),
						legendtitle, siDto.getIndicatorName());
			}
		}
		return defaultcategorydataset;
	}
}